import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 预期浏览器会发一个形如 /getParameter?studentId=10&classId=20 请求
        // 借出 req 里的 getParameter 方法就能拿到 query string 中的键值对内容了
        // getParameter 得到的是 string 类型的结果
        String studentId = req.getParameter("studentId");
        String classId = req.getParameter("classId");
        resp.setContentType("text/html; charset = utf-8");
        //resp.setCharacterEncoding("utf-8");
        resp.getWriter().write("学生Id = " + studentId + "班级Id = " + classId);
    }
}
